<?php
    header("Content-Type:text/json;charset=utf-8");

    $con = mysqli_connect("127.0.0.1","root","","xxy");
    //判断是否已经建立链接
    if(!$con){
        printf("Can't connect to MySQL Server. Errorcode: %s ",mysqli_connect_error());
        exit;
    }
    $sql = "SELECT * FROM book";

    //响应一个结果
    $result = mysqli_query($con,$sql);
    $list=array();
    //获取这个结果
    while($row = mysqli_fetch_array($result)){
        //怎么拿到数据
        //$row代表的是一行数据
        $item = array(
            "id" =>  $row["id"],
            "bookName" => $row["bookName"],
            "author" => $row["author"],
            "price" => $row["price"],
            "cbs" => $row["cbs"],
            "operation"=>"删除"
        );
        array_push($list,$item);
    }
    $json = json_encode($list);

    echo $json;
    //关闭连接
    mysqli_close($con);

?>